package cn.fl.capital.controller;

import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.capital.condition.CapAccBalanceQueryCondition;
import cn.fl.capital.service.ICapAccBalanceService;
import cn.fl.capital.vo.CapAccBalanceVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Description: 账务结余（车立行） 控制层
 */
@Controller
@RequestMapping("/capital/capAccBalance")
public class CapAccBalanceController extends BaseController {
	private static final Logger logger = LoggerFactory.getLogger(CapAccBalanceController.class);
	
	/**
	 * CapAccBalance 服务层BEAN
	 */
	@Autowired
	private ICapAccBalanceService capAccBalanceService;

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		BaseLogUtils.info(logger, "toListPage", "加载CapAccBalance列表页面.",CurrentThreadContext.getCurrentUserName());
		ModelAndView mav = new ModelAndView("capital/capAccBalance/capAccBalanceList");
		return mav;
	}
	
	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initCapAccBalanceList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		CapAccBalanceQueryCondition qc = new CapAccBalanceQueryCondition();
		String cstNm = request.getParameter("cstNm");
		if (StringUtils.isNotBlank(cstNm)) {
			qc.setCstNm(cstNm);
		}
		String paySchNo = request.getParameter("paySchNo");
		if(StringUtils.isNotBlank(paySchNo)){
			qc.setPaySchNo(paySchNo);
		}
		String payDtMax = request.getParameter("payDtMax");
		if(StringUtils.isNotBlank(payDtMax)){
			qc.setPayDtMax(payDtMax);
		}
		String payDtMin = request.getParameter("payDtMin");
		if(StringUtils.isNotBlank(payDtMin)){
			qc.setPayDtMin(payDtMin);
		}
		String lkPayDtMax = request.getParameter("lkPayDtMax");
		if(StringUtils.isNotBlank(lkPayDtMax)){
			qc.setLkPayDtMax(lkPayDtMax);
		}
		String lkPayDtMin = request.getParameter("lkPayDtMin");
		if(StringUtils.isNotBlank(lkPayDtMin)){
			qc.setLkPayDtMin(lkPayDtMin);
		}
		page.setCondition(qc);

		BaseLogUtils.info(logger, "initCapAccBalanceList", "初始化CapAccBalance列表页面数据.DATA:"+JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		Pager pager = this.capAccBalanceService.searchListPage(page);
		List<CapAccBalanceVO> list = (List<CapAccBalanceVO>) pager.getResultList();
		ListPageVO<CapAccBalanceVO> listPage = new ListPageVO<CapAccBalanceVO>(list, pager.getTotalCount());
		return listPage;
	}

}

